﻿using lwzlz.Application.System;
using lwzlz.Application.System.Dto;
using lzwlz.Web;
using System;
using System.Web.Mvc.Filters;
using System.Web.Routing;

namespace lwzlz.Web
{
    public class MallController : BaseController
    {
        /// <summary>
        /// 在进行授权时调用
        /// </summary>
        /// <param name="filterContext"></param>
        protected override void OnAuthentication(AuthenticationContext filterContext)
        {
            MemberLogin Member = lzwlz.Web.MallMemberLogin.GetCurrentUser();

            if (Member == null || Member.Id == 0)
            {
                //未登录
                filterContext.Result = RedirectToRoute(new { area = "Mall", controller = "Login", action = "Index" });
            }

            base.OnAuthentication(filterContext);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="requestContext"></param>
        /// <param name="callback"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        protected override IAsyncResult BeginExecute(RequestContext requestContext, AsyncCallback callback, object state)
        {
            var memberLogin = MallMemberLogin.GetCurrentUser();
            if (memberLogin != null)
            {
                ViewData["WebHeadMember"] = memberLogin;
                ViewData["WebHeadAddressList"] = new AddressService().GetList(memberLogin.Id);
                ViewData["WebHeadShoppingCartList"] = new ShoppingCartService().GetList(memberLogin.Id);
            }
            return base.BeginExecute(requestContext, callback, state);
        }
    }
}